<?php

print "Printing float with 17 significant digits
0.12345678901234567 <- i.e. this one\n";
print 0.12345678901234567;
print "\n..trying printf(\"%f\", 0.12345678901234567)\n";
printf("%f", 0.12345678901234567);
print "\n..trying printf(\"%.17f\", 0.12345678901234567)\n";
printf("%.17f", 0.12345678901234567);
print "\n\n";

print "Getting more digits with %f";
print "\n..printf(\"%.17f\", 0.12345678901234567)\n";
printf("%.17f", 0.12345678901234567);
print "\n..printf(\"%.20f\", 0.12345678901234567)\n";
printf("%.20f", 0.12345678901234567);
print "\n..printf(\"%.60f\", 0.12345678901234567)\n";
printf("%.60f", 0.12345678901234567);
print "\n\n";


print serialize(0.12345678901234567);
print "\n\n";

print "Checking how PHP serializes floats.\n";

function check($z) {
    $sz = serialize($z);
    $usz = unserialize($sz);
    print $z." ".$sz." ".$usz." ".serialize($usz)."\n";
}

print "Testing numbers for num, serialized, unserialized, reserialized:
0.12345678901234567890123456789
0.12345678901234567
0.1234567890123456
0.123456789012
\n";
check(0.12345678901234567890123456789);
check(0.12345678901234567);
check(0.1234567890123456);
check(0.123456789012);

print "\nTest unserialization";
printf("\n%.60f is restored from d:0.12345678901234567;",
  unserialize("d:0.12345678901234567;"));
printf("\n%.60f is restored from d:0.12345678901234566904321354741114191710948944091796875;",
  unserialize("d:0.12345678901234566904321354741114191710948944091796875;"));


print "\n\nFloat miscalculation\n";

print(floor( (0.8)*10     ));
print "\n";
print(floor( (0.1+0.7)*10 ));
print "\n";
